package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Fragment.DeclareCommodityFg;
import com.ydkj.a37e_mall.Classes.Fragment.DistributionOrderFg;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

/**
 * Created by Administrator on 2017/1/13.
 * 我的门店
 */

public class MystoreActivity extends BaseActivity implements View.OnClickListener {
    private MyApplication myApplication;
    private TextView tv_distribution_order, tv_declare_commodity, tv_business_tb, tv_store_administration, tv_consumption_declare, tv_stay_declare_commodity;
    private TextView tv_mystore1, tv_mystore2, tv_mystore3, tv_mystore4;
    private Activity mActivity;
    private ImageView img_back;
    private FragmentManager fragmentManager;

    private DistributionOrderFg distributionOrderFg;//配送订单
    private DeclareCommodityFg declareCommodityFg;//申报商品

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mystorelayout);
        mActivity = this;
        init();
//        initWindow();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);

    }

    private void init() {
        myApplication = MyApplication.getInstance();
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();

        distributionOrderFg = new DistributionOrderFg();
        declareCommodityFg = new DeclareCommodityFg();

        ft.add(R.id.fly_mystore, distributionOrderFg, "one");
        ft.commitAllowingStateLoss();

        tv_distribution_order = (TextView) mActivity.findViewById(R.id.tv_distribution_order);
        tv_declare_commodity = (TextView) mActivity.findViewById(R.id.tv_declare_commodity);
        tv_business_tb = (TextView) mActivity.findViewById(R.id.tv_business_tb);
        tv_store_administration = (TextView) mActivity.findViewById(R.id.tv_store_administration);
        tv_stay_declare_commodity = (TextView) mActivity.findViewById(R.id.tv_stay_declare_commodity);

        tv_mystore1 = (TextView) mActivity.findViewById(R.id.tv_mystore1);
        tv_mystore2 = (TextView) mActivity.findViewById(R.id.tv_mystore2);
        tv_mystore3 = (TextView) mActivity.findViewById(R.id.tv_mystore3);
        tv_mystore4 = (TextView) mActivity.findViewById(R.id.tv_mystore4);


        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        tv_distribution_order.setSelected(true);

        tv_distribution_order.setOnClickListener(this);
        tv_declare_commodity.setOnClickListener(this);
        tv_business_tb.setOnClickListener(this);
        tv_store_administration.setOnClickListener(this);
        tv_stay_declare_commodity.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        FragmentTransaction ft;
        switch (view.getId()) {
            case R.id.tv_stay_declare_commodity://待申报商品
                startActivity(new Intent(mActivity, StaydeclareCommActivity.class));
                break;
            case R.id.tv_distribution_order://配送订单
                tv_distribution_order.setSelected(true);
                tv_declare_commodity.setSelected(false);
                tv_business_tb.setSelected(false);
                tv_store_administration.setSelected(false);

                tv_mystore1.setVisibility(View.VISIBLE);
                tv_mystore2.setVisibility(View.INVISIBLE);
                tv_mystore3.setVisibility(View.INVISIBLE);
                tv_mystore4.setVisibility(View.INVISIBLE);

                ft = fragmentManager.beginTransaction();

                if (declareCommodityFg.isAdded()) {
                    ft.hide(declareCommodityFg);
                    declareCommodityFg.onPause();
                }

                ft.show(distributionOrderFg);
                ft.commit();
                break;
            case R.id.tv_declare_commodity://申报商品
                tv_distribution_order.setSelected(false);
                tv_declare_commodity.setSelected(true);
                tv_business_tb.setSelected(false);
                tv_store_administration.setSelected(false);

                tv_mystore1.setVisibility(View.INVISIBLE);
                tv_mystore2.setVisibility(View.VISIBLE);
                tv_mystore3.setVisibility(View.INVISIBLE);
                tv_mystore4.setVisibility(View.INVISIBLE);

                ft = fragmentManager.beginTransaction();

                if (distributionOrderFg.isAdded()) {
                    ft.hide(distributionOrderFg);
                    distributionOrderFg.onPause();
                }

                if (declareCommodityFg.isAdded()) {
                    ft.show(declareCommodityFg);
                } else {
                    ft.add(R.id.fly_mystore, declareCommodityFg, "two");
                    ft.show(declareCommodityFg);
                }
                ft.commit();
                break;
            case R.id.tv_business_tb://营业通宝
                startActivity(new Intent(mActivity, BusinessTbActivity.class));
                break;
            case R.id.tv_store_administration://门店管理
                myApplication.setStorename3("");
                myApplication.setMobile3("");
                myApplication.setAddress3("");
                myApplication.setDescription3("");
                myApplication.setName3("");
                myApplication.setMobile3("");
                myApplication.setIDnumber3("");
                myApplication.setBanknumber3("");
                myApplication.setBankname3("");
                myApplication.setPaypswd3("");
                myApplication.setPaypswd3_1("");
                myApplication.setIntent_code(5);
                startActivity(new Intent(mActivity, StoreManagementActivity.class));

                break;

        }
    }
}
